package com.tansuo365.test1.controller.othercontrol;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tansuo365.test1.bean.otherbean.DBumen;
import com.tansuo365.test1.service.otherservice.DBumenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/dbumen")
public class DBumenController {

    @Autowired
    private DBumenService dBumenService;

    @RequestMapping("/getSelective")
    public Map<String,Object> getDBumen(DBumen dBumen,@RequestParam(value="page",required=true)Integer page, @RequestParam(value="rows",required=true)Integer rows){
        Map<String, Object> resultMap = new HashMap<>();
        PageHelper.startPage(page, rows);
        List<DBumen> byWaiId = dBumenService.findSelective(dBumen);
        PageInfo<DBumen> pageInfo = new PageInfo<DBumen>(byWaiId);
        resultMap.put("rows", pageInfo.getList());
        resultMap.put("total", pageInfo.getTotal());
        return resultMap;
    }

    @RequestMapping("/save")
    public Map<String, Object> save(DBumen dBumen) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dBumenService.insertSelective(dBumen);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

    @RequestMapping("/update")
    public Map<String, Object> update(DBumen dBumen) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dBumenService.updateByPrimaryKeySelective(dBumen);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

    @RequestMapping("/delete")
    public Map<String, Object> delete(@RequestParam("ids[]") Integer[] ids) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dBumenService.deleteBatchByPKArr(ids);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

}
